/**
 * Copyright 2011 rkehoe
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 * 
 */
package example.domain.objects;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import example.domain.objects.Colour;
import example.domain.objects.Manufacturer;
import example.domain.objects.Vehicle;
import example.domain.objects.VehicleType;


/**
 * A Builder for [semi-] random test Vehicles.
 * 
 * @author RK
 *
 */
public class VehicleBuilder
{
	private Manufacturer manufacturer;
	private Colour colour;
	private VehicleType vehicleType;
	private String model;
	private double weight;
	private int seats;
	private int doors;
	private int engineCapacity;
		
    public VehicleBuilder(Colour colour, Manufacturer manufacturer, VehicleType vehicleType, String model, double weight, int seats, int doors, int engineCapacity)
    {
		this.colour = colour;
		this.manufacturer = manufacturer;
		this.vehicleType = vehicleType;
		this.model = model;
		this.weight = weight;
		this.seats = seats;
		this.doors = doors;
		this.engineCapacity = engineCapacity;
    }

	public VehicleBuilder with(Colour colour)
	{
    	return new VehicleBuilder(colour,manufacturer, vehicleType, model, weight,seats,doors,engineCapacity);    	
	}

	public VehicleBuilder notWith(Colour colour)
	{
    	return new VehicleBuilder(Colour.not(colour),manufacturer, vehicleType, model, weight,seats,doors,engineCapacity);    	
	}
    
	public VehicleBuilder with(Manufacturer m)
    {
    	return new VehicleBuilder(colour,m, vehicleType, model, weight,seats,doors,engineCapacity);    	
    }

	public VehicleBuilder notWith(Manufacturer m)
    {
    	return new VehicleBuilder(colour,Manufacturer.not(m), vehicleType, model, weight,seats,doors,engineCapacity);    	
    }

	public VehicleBuilder with(VehicleType t)
    {
    	return new VehicleBuilder(colour,manufacturer, t, model, weight,seats,doors,engineCapacity);    	
    }

	public VehicleBuilder notWith(VehicleType t)
    {
    	return with(VehicleType.not(t));    	
    }

    public static VehicleBuilder create()
    {
		return new VehicleBuilder(Colour.random(),Manufacturer.random(),VehicleType.random(),"Model X", 1000,4,2,1800);
    }

    public Collection<Vehicle> build(int size)
    {
    	List<Vehicle> list = new ArrayList<Vehicle>(size);
    	for (int i = 0; i < size; i++)
        {
    		list.add(build());
        }
	    return list;
    }

    public Vehicle build()
    {
    	return new Vehicle(colour,manufacturer, vehicleType, model, weight,seats,doors,engineCapacity);
    }
}
